<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <%response.setCharacterEncoding("UTF-8");
    request.setCharacterEncoding("UTF-8");%>
</head>
<body>
<div class=kontakt>
<% //czesc dostępna dla wszystkich (error nie masz uprawnień)
HttpSession sesja = request.getSession(true);
Connection con = mb.commons.DbConnection.getConnection();
Statement stmt = con.createStatement();
if(!sesja.getAttribute("log").equals("admin") && !sesja.getAttribute("log").equals("kurier") &&
		!sesja.getAttribute("log").equals("klient")	&& !sesja.getAttribute("log").equals("pracownik")){	
	if(sesja.getAttribute("lang").equals("en")){%>
	<br><img src="images/stop.png" width=30% height=30%><br><br>
	<h1>ACCESS DANIED</h1><br>
	You don't have permission to access this page.<br>
	Log in first.
	<br><br>	
	<%}else{ %>
	<br><img src="images/stop.png" width=30% height=30%><br><br>
	<h1>DOSTĘP ZABRONIONY</h1><br>
	Nie masz uprawnień do oglądania tej strony.<br>
	Zaloguj się najpierw.
	<br><br>
<%}}else{//czesc dostepna tylko po zalogowaniu
	String login = sesja.getAttribute("nick").toString();
	String rodzaj = sesja.getAttribute("log").toString();
	String imie=null;
	String nazwisko=null;
	String adres=null;
	String kod=null;
	String miasto=null;
	String mail=null;
	String data_rej=null;
	String data_log=null;
	String pesel = null;
	String status=null;
	int id_oddzialu = 0;
%>
<br>
<div class=formularz>
<fieldset class='obrys'>
<div id=info class=info>&nbsp;</div>
<div class=opcje>
<form id=rejestracja name=rejestracja method=post onSubmit='Ustawienia()' action=#>
<table class=opcje >
<tr>
<td align="center" valign="middle"> 
	
	<%
	if(rodzaj.equals("klient")){
		ResultSet rs = stmt.executeQuery("SELECT k.imie,k.nazwisko,k.adres,k.kod,k.miasto,u.mail,u.data_rej,u.ostatnie_log FROM uzytkownicy u, klienci k WHERE u.login = '"+login+"' and u.id=k.id");
		while(rs.next()){
			  imie = rs.getString("imie");
			  nazwisko = rs.getString("nazwisko");
			  adres = rs.getString("adres");
			  kod = rs.getString("kod");
			  miasto = rs.getString("miasto");
			  mail = rs.getString("mail");
			  data_rej = rs.getString("data_rej");
			  data_log = rs.getString("ostatnie_log");				
			  }			  
		  }		
	if(rodzaj.equals("pracownik")){
		ResultSet rs = stmt.executeQuery("SELECT k.imie,k.nazwisko,k.adres,k.kod,k.miasto,k.pesel,k.status,k.id_oddzialu,u.mail,u.data_rej,u.ostatnie_log FROM uzytkownicy u, pracownicy k WHERE u.login = '"+login+"' and u.id=k.id");
		while(rs.next()){
			  imie = rs.getString("imie");
			  nazwisko = rs.getString("nazwisko");
			  adres = rs.getString("adres");
			  kod = rs.getString("kod");
			  miasto = rs.getString("miasto");
			  mail = rs.getString("mail");
			  data_rej = rs.getString("data_rej");
			  data_log = rs.getString("ostatnie_log");	
			  pesel = rs.getString("pesel");
			  status=rs.getString("status");
			  id_oddzialu = rs.getInt("id_oddzialu");
			  }			  
		  }		
	if(rodzaj.equals("kurier")){
		ResultSet rs = stmt.executeQuery("SELECT k.imie,k.nazwisko,k.adres,k.kod,k.miasto,k.pesel,k.status,k.id_oddzialu,u.mail,u.data_rej,u.ostatnie_log FROM uzytkownicy u, kurierzy k WHERE u.login = '"+login+"' and u.id=k.id");
		while(rs.next()){
			  imie = rs.getString("imie");
			  nazwisko = rs.getString("nazwisko");
			  adres = rs.getString("adres");
			  kod = rs.getString("kod");
			  miasto = rs.getString("miasto");
			  mail = rs.getString("mail");
			  data_rej = rs.getString("data_rej");
			  data_log = rs.getString("ostatnie_log");	
			  pesel = rs.getString("pesel");
			  status=rs.getString("status");
			  id_oddzialu = rs.getInt("id_oddzialu");
			  }			  
		  }		
	if(rodzaj.equals("admin")){
		ResultSet rs = stmt.executeQuery("SELECT u.mail,u.data_rej,u.ostatnie_log FROM uzytkownicy u WHERE u.login = '"+login+"'");
		while(rs.next()){
			  mail = rs.getString("mail");
			  data_rej = rs.getString("data_rej");
			  data_log = rs.getString("ostatnie_log");	
			  }			  
		  }	
	if(sesja.getAttribute("lang").equals("en")){%> 
	<table>
	<tr>
		<td>Login:</td><td><input type='text' size='25' name='login' disabled='disabled' value='<%out.println(login);%>'/></td>
	</tr>
	<tr>
		<td>Account type:</td><td><input type='text' size='25' name='typ' disabled='disabled' value='<%out.println(rodzaj);%>'/></td>
	</tr>
	<%if(!rodzaj.equals("admin")){%>
	<tr>
		<td>Name:</td><td><input type='text' id='imie' size='25' name='imie' value='<%out.println(imie);%>'/></td><td id=td1></td>
	</tr>
	<tr>
		<td>Surname:</td><td><input type='text' id='nazwisko' size='25' name='nazwisko' value='<%out.println(nazwisko);%>'/></td><td id=td2></td>
	</tr>
	<tr>
		<td>Address:</td><td><input type='text' id='adres' size='25' name='adres' value='<%out.println(adres);%>'/></td><td id=td3></td>
	</tr>
	<tr>
		<td>Postal code:</td><td><input type='text' size='25' name='kod' id=kod onKeyPress='TylkoKodPocztowy(event)' value='<%out.println(kod);%>'/></td><td id=td4></td>	
	</tr>
	<tr>
		<td>City:</td><td><input type='text' size='25' name='miasto'  value='<%out.println(miasto);%>'/></td><td id=td5></td>	
	</tr>
	<%}%>
	<tr>
		<td>E-mail:</td><td><input id='mail' type='text' size='25' name='mail' value='<%out.println(mail);%>'/></td><td id=td6></td>
	</tr>
	<tr>
		<td>Password:</td><td><input type='password' size='25' name='password' value='password' disabled='disabled'/></td><td><input class=przycisk type='button' name='clean' value='Change' onClick='ZmHaslo()'>
	</tr>
	<%if(rodzaj.equals("kurier") || rodzaj.equals("pracownik")){ %>
	<tr>
		<td>ID number:</td><td><input type='text' size='25' name='pesel' disabled='disabled' id=pesel value='<%out.println(pesel);%>'/></td><td><input class=przycisk type='button' name='clean' value='Change' onClick='ZmPesel()'></td>	
	</tr>
	<tr>
		<td>Status:</td><td><input type='text' size='25' name='status' disabled='disabled' value='<%out.println(status);%>'/></td><td><input class=przycisk type='button' name='clean' value='Change' onClick='ZmPesel()'></td>
	</tr>
	<tr>
		<td>Outpost ID:</td><td><input id='id_oddzialu' type='text' size='25' name='id_oddzialu' disabled='disabled' value='<%out.println(id_oddzialu);%>'/></td><td><input class=przycisk type='button' name='clean' value='Change' onClick='ZmPesel()'></td>
	</tr>
	<% }%>
	<tr>
		<td>Registration date:</td><td><input type='text' size='25' name='data' disabled='disabled' value='<%out.println(data_rej);%>'/></td>
	</tr>
	<tr>
		<td>Last visit:</td><td><input type='text' size='25' name='data2' disabled='disabled' value='<%out.println(data_log);%>'/></td>
	</tr>
	</table>
  </td>
 </tr>
</table>
<input class=przycisk type='button' id='ok' name='ok' value='Save changes' onClick='Ustawienia()'>
<input class=przycisk type='button' name='clean' value='     Cancel     ' onClick='this.form.reset()'>
	<%}else{ %>
		<table>
	<tr>
		<td>Login:</td><td><input type='text' size='25' name='login' disabled='disabled' value='<%out.println(login);%>'/></td>
	</tr>
	<tr>
		<td>Typ konta:</td><td><input type='text' size='25' name='typ' disabled='disabled' value='<%out.println(rodzaj);%>'/></td>
	</tr>
	<%if(!rodzaj.equals("admin")){%>
	<tr>
		<td>Imię:</td><td><input type='text' id='imie' size='25' name='imie' value='<%out.println(imie);%>'/></td><td id=td1></td>
	</tr>
	<tr>
		<td>Nazwisko:</td><td><input type='text' id='nazwisko' size='25' name='nazwisko' value='<%out.println(nazwisko);%>'/></td><td id=td2></td>
	</tr>
	<tr>
		<td>Adres:</td><td><input type='text' id='adres' size='25' name='adres' value='<%out.println(adres);%>'/></td><td id=td3></td>
	</tr>
	<tr>
		<td>Kod pocztowy:</td><td><input type='text' size='25' name='kod' id=kod onKeyPress='TylkoKodPocztowy(event)' value='<%out.println(kod);%>'/></td><td id=td4></td>	
	</tr>
	<tr>
		<td>Miasto:</td><td><input type='text' size='25' name='miasto'  value='<%out.println(miasto);%>'/></td><td id=td5></td>	
	</tr>
	<%}%>
	<tr>
		<td>E-mail:</td><td><input alt='ee' id='mail' type='text' size='25' name='mail' value='<%out.println(mail);%>'/></td><td id=td6></td>
	</tr>
	<tr>
		<td>Hasło:</td><td><input type='password' size='25' name='password' value='password' disabled='disabled'/></td><td><input class=przycisk type='button' name='clean' value='Zmień' onClick='ZmHaslo()'>
	</tr>
	<%if(rodzaj.equals("kurier") || rodzaj.equals("pracownik")){ %>
	<tr>
		<td>Pesel:</td><td><input type='text' size='25' name='pesel' disabled='disabled' id=pesel value='<%out.println(pesel);%>'/></td><td><input class=przycisk type='button' name='clean' value='Zmień' onClick='ZmPesel()'></td>	
	</tr>
	<tr>
		<td>Status:</td><td><input type='text' size='25' name='status' disabled='disabled' value='<%out.println(status);%>'/></td><td><input class=przycisk type='button' name='clean' value='Zmień' onClick='ZmPesel()'></td>
	</tr>
	<tr>
		<td>Id dddziału:</td><td><input id='id_oddzialu' type='text' size='25' name='id_oddzialu' disabled='disabled' value='<%out.println(id_oddzialu);%>'/></td><td><input class=przycisk type='button' name='clean' value='Zmień' onClick='ZmPesel()'></td>
	</tr>
	<% }%>
	<tr>
		<td>Data rejestracji:</td><td><input type='text' size='25' name='data' disabled='disabled' value='<%out.println(data_rej);%>'/></td>
	</tr>
	<tr>
		<td>Ostatnie logowanie:</td><td><input type='text' size='25' name='data2' disabled='disabled' value='<%out.println(data_log);%>'/></td>
	</tr>
	</table>
  </td>
 </tr>
</table>
<input class=przycisk type='button' id='ok' name='ok' value='Zapisz zmiany' onClick='Ustawienia()'>
<input class=przycisk type='button' name='clean' value='     Anuluj     ' onClick='this.form.reset()'>
	<%}%>
</form>
</div>
</fieldset>
</div>
<%}%>
</div>	
</body>
</html>